package sdfi.lee.Entity.base;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * This is an object that contains data related to the person table.
 * Do not modify this class because it will be overwritten if the configuration file
 * related to this class is modified.
 *
 * @hibernate.class
 *  table="person"
 */

public abstract class BasePerson  implements Serializable {

	public static String REF = "Person";
	public static String PROP_PERSONDESCRIBE = "persondescribe";
	public static String PROP_PERSONNAME = "personname";
	public static String PROP_ID = "id";
	public static String PROP_PERSONSEX = "personsex";
	public static String PROP_PERSONNATION = "personnation";


	// constructors
	public BasePerson () {
		initialize();
	}

	/**
	 * Constructor for primary key
	 */
	public BasePerson (java.lang.Integer id) {
		this.setId(id);
		initialize();
	}

	protected void initialize () {}



	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private java.lang.Integer id;

	// fields
	private java.lang.String personname;
	private java.lang.Integer persontype;
	private java.lang.String persondescribe;
	private java.lang.String personPath;
	


	/**
	 * Return the unique identifier of this class
     * @hibernate.id
     *  generator-class="identity"
     *  column="Id"
     */
	public java.lang.Integer getId () {
		return id;
	}

	/**
	 * Set the unique identifier of this class
	 * @param id the new ID
	 */
	public void setId (java.lang.Integer id) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}




	/**
	 * Return the value associated with the column: personname
	 */
	public java.lang.String getPersonname () {
		this.getPath(this.getPersondescribe());
		return personname;
	}

	/**
	 * Set the value related to the column: personname
	 * @param personname the personname value
	 */
	public void setPersonname (java.lang.String personname) {
		this.personname = personname;
	}



	/**
	 * Return the value associated with the column: personsex
	 */






	/**
	 * Return the value associated with the column: persondescribe
	 */
	public java.lang.String getPersondescribe () {
		return persondescribe.replace("/project", "");
	}

	/**
	 * Set the value related to the column: persondescribe
	 * @param persondescribe the persondescribe value
	 */
	public void setPersondescribe (java.lang.String persondescribe) {
		this.persondescribe = persondescribe;
	}




	public java.lang.String getPersonPath() {
		
		this.getPath(this.persondescribe);
		return personPath;
	}

	public void setPersonPath(java.lang.String personPath) {
		this.personPath = personPath;
	}
	private void getPath(String source)
	{
		
		try
		{
			
			
			if(source!=null)
			{
			String regex="/userfiles.+[jpg][gif]";
			Pattern pattern=Pattern.compile(regex);
			Matcher matcher=pattern.matcher(source);
			if(matcher.find())
			{
				this.personPath=matcher.group().replace("/project", "");
				
			}
			}
			
	
		}
		catch(Exception ee)
		{
			System.out.println("Exception when get person pictrue");
			ee.printStackTrace();
		}
		
		
	}
	public boolean equals (Object obj) {
		if (null == obj) return false;
		if (!(obj instanceof sdfi.lee.Entity.Person)) return false;
		else {
			sdfi.lee.Entity.Person person = (sdfi.lee.Entity.Person) obj;
			if (null == this.getId() || null == person.getId()) return false;
			else return (this.getId().equals(person.getId()));
		}
	}

	public int hashCode () {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getId()) return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}
	

	public String toString () {
		return super.toString();
	}

	public java.lang.Integer getPersontype() {
		return persontype;
	}

	public void setPersontype(java.lang.Integer persontype) {
		this.persontype = persontype;
	}


}